package com.ht.pms.core.controller.dictParams;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ht.pms.core.dto.PageResult;
import com.ht.pms.core.dto.dict.DictParamsDto;
import com.ht.pms.core.dto.dict.DictParamsReq;
import com.ht.pms.core.dto.tempalte.TemplateReq;
import com.ht.pms.core.service.SalaryBusinessDictService;
import com.ht.ussp.core.Result;

//@CrossOrigin
@RestController
@RequestMapping("/salaryDictParams")
public class SalaryDictParamsController {
	private static final Logger LOGGER = LoggerFactory.getLogger(SalaryDictParamsController.class);
	
	@Autowired
	private SalaryBusinessDictService salaryBusinessDictService;
	/**
	 * 获取模板列表
	 * 
	 * @param tableName
	 * @return
	 */
	@RequestMapping("/getDictParamList")
	public PageResult<List<DictParamsDto>> getTemplateList(TemplateReq req) {
		LOGGER.info("[字段管理] 获取字段列表  params:[{}]", req);
		List<DictParamsDto> templateList = salaryBusinessDictService.getDictParamList(req);
		int templateCount = salaryBusinessDictService.getDictParamCount(req);

		return PageResult.success(templateList, templateCount);
	}
	
	
	/**
	 * 保存字段
	 * 
	 * @param tableName
	 * @return
	 */
	@RequestMapping("/saveDictParam")
	public Result saveDictParam(@RequestBody DictParamsReq req) {
		LOGGER.info("[字段管理] 保存字段  params:[{}]", req);
		salaryBusinessDictService.saveDictParam(req);

		return Result.buildSuccess();
	}
	
	/**
	 * 查询字段
	 * 
	 * @param tableName
	 * @return
	 */
	@RequestMapping("/getDictParam")
	public Result<DictParamsDto> getDictParam(@RequestParam("dictCode") String dictCode) {
		LOGGER.info("[字段管理] 保存字段  dictCode:[{}]", dictCode);
		DictParamsDto dictParamsDto = salaryBusinessDictService.getDictParam(dictCode);

		return Result.buildSuccess(dictParamsDto);
	}
}
